/**
 * 
 */
package org.rollinitiative.d20;

/**
 * @author bebopjmm
 * 
 */
public class AdjustmentLimiter implements AdjustmentListener
{

    Adjustment parent_;

    Adjustment limiter_;


    public AdjustmentLimiter(Adjustment parent, int limit)
    {
        this.parent_ = parent;
        limiter_ = new Adjustment(parent.getType(), parent.getValue(), parent.getDescription());
        parent.subscribe(this);
        limiter_.setLimit(limit);
    }


    public Adjustment getLimitedAdjustment()
    {
        return limiter_;
    }


    public void clear()
    {
        parent_.unsubscribe(this);
        parent_ = null;
        limiter_ = null; // may need ensure all subscriptions are cleared.
    }


    @Override
    public void valueChanged(Adjustment adjustment)
    {
        limiter_.setValue(adjustment.getValue());

    }
}
